﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LibraryO2S;

public partial class Administrator_townedit : System.Web.UI.Page
{
    private TownController objTown = new TownController();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getData();
        }
    }

    private void getData()
    {
        DataTable dtTown = objTown.GetByID(getID());
        txtIndex.Text = dtTown.Rows[0]["SORTDISPLAY"].ToString();
        txtName.Text = dtTown.Rows[0]["TOWNNAME"].ToString();
        if (dtTown.Rows[0]["STATUS"].ToString() == "1")
        {
            chkStatus.Checked = true;
        }
        else
        {
            chkStatus.Checked = false;
        }

    }

    public string getID()
    {
        string id = "";
        try
        {
            id = Request.QueryString["town_id"].ToString();
        }
        catch
        {
        }
        return id;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string name = txtName.Text.Trim();
        string index = txtIndex.Text.Trim();
        string status = "0";
        if (chkStatus.Checked == true)
        {
            status = "1";
        }
        bool kt = objTown.Update(getID(), name, index, status);
        if (kt == true)
        {
            Response.Redirect("town.aspx");
        }
        else
        {
            divMessage.InnerHtml = O2S_Message.Warning("Cảnh báo", "Cập nhật không thành công!");
        }
    }
}